package com.global.college.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.global.college.R;
import com.global.college.UserData;
import com.global.college.base.BaseActivity;
import com.global.college.ui.interfaces.ICacheView;
import com.global.college.utils.AppManagerUtils;
import com.global.college.utils.CommonUtils;
import com.global.college.utils.HsSetCacheUtil;
import com.global.college.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置中心
 */
public class SettingActivity extends BaseActivity implements ICacheView {


    @BindView(R.id.ll_modify_phone)
    LinearLayout llModifyPhone;
    @BindView(R.id.ll_play_set)
    LinearLayout llPlaySet;
    @BindView(R.id.tv_cache)
    TextView tvCache;
    @BindView(R.id.ll_about_us)
    LinearLayout llAboutUs;
    @BindView(R.id.ll_app_version)
    LinearLayout llAppVersion;
    @BindView(R.id.tv_login_out)
    TextView tvLoginOut;
    @BindView(R.id.tv_app_version)
    TextView tvAppVersion;
    private HsSetCacheUtil hsSetCacheUtil;

    @Override
    public int getContentViewId() {
        return R.layout.activity_setting;
    }

    @Override
    public void onCreateNew(Bundle savedInstanceState) {
/*        setShowTitleBar(true);
        setShowBack(true);
        setTitle("设置");*/

        setShowTitleBar(false);
    }

    @Override
    public void getInitData() {
        hsSetCacheUtil = new HsSetCacheUtil(this);
        hsSetCacheUtil.setICacheView(this);
        hsSetCacheUtil.getAppCache();
        tvAppVersion.setText("V " + CommonUtils.getVersion(this));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        useImmersionBar = false;
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.ll_modify_psw, R.id.ll_modify_phone, R.id.ll_play_set, R.id.tv_cache, R.id.ll_clear_cache, R.id.ll_about_us, R.id.ll_app_version, R.id.tv_login_out,R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_modify_psw:
                openActivity(ModifyPswActivity.class);
                break;
            case R.id.ll_modify_phone:
                openActivity(ModifyPhoneActivity.class);
                break;
            case R.id.ll_play_set:
                break;
            case R.id.tv_cache:
            case R.id.ll_clear_cache:
                hsSetCacheUtil.cleanCache();
                break;
            case R.id.ll_about_us:
                openActivity(AboutUsActivity.class);
                break;
            case R.id.ll_app_version:
                ToastUtils.showCenterToast("已是最新版本");
                break;
            case R.id.tv_login_out:
                //清空用户缓存数据
                UserData.getInstance().ClearAllCachData();
                AppManagerUtils.getInstance().finishAllActivity();
                openActivity(LoginByPswActivity.class);
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    public void onGetCacheSuccess(String cache) {
        tvCache.setText(cache);
    }

    @Override
    public void onGetDeleteeCacheSuccess(String cache) {
        tvCache.setText(cache);
    }
}